import dayjs from 'dayjs';
import { Entity, Column, Index } from 'typeorm';
import { CommonEntity } from '~/common/entity/common.entity';
import { WeatherFileType } from './weather.model';

export enum WarningCode {
  CRGM = 'CRGM', // 青年感冒
  CNGM = 'CNGM', // 青年感冒
  HF = 'HF', // 花粉过敏
	// 补充
	LNGM = 'LNGM', // 老年人感冒气象风险
	LRGM = 'LRGM', // 老年人感冒气象风险
  QNGM = 'QNGM', // 成人感冒气象风险
  QRGM = 'QRGM', // 成人感冒气象风险
  ZS = 'ZS',     // 中暑气象风险
  COPD = 'COPD', // 慢阻肺气象环境风险
  POLLEN = 'POLLEN' // 花粉指数
}

@Entity('ah_weather')
@Index(['id'])
export class WeatherEntity extends CommonEntity {
  @Column({ type: 'enum', enum: WarningCode, default: WarningCode.COPD, comment: '天气预警代码' })
  code: string; // COPD、CRGM 等简码

  @Column({ name: 'name', type: 'varchar', length: 100, nullable: true, comment: '天气预警名称' })
  name?: string; // 青年感冒 / 中暑等名称

	@Column({name: 'file_name', type: 'varchar', length: 100, comment: '文件名称'})
	fileName: string;

  @Column({
    name: 'date',
    type: 'date',
    transformer: {
      to: (value: Date) => value,
      from: (value: string) => dayjs(value).format('YYYY-MM-DD'),
    },
		comment: '预警日期',
  })
  date: Date;

  @Column({ name: 'risk_level', type: 'varchar', length: 50, nullable: true, comment: '风险等级' })
  riskLevel: string; // 风险等级

  @Column({ name: 'risk_level_code', type: 'varchar', length: 50, nullable: true, comment: '风险等级代码' })
  riskLevelCode: string; // 风险等级代码

  @Column({ name: 'risk_level_description', type: 'varchar', length: 200, nullable: true, comment: '风险预防人群' })
  targetPopulation: string; // 防范人群

  @Column({ name: 'prevention_suggestion', type: 'varchar', length: 500, nullable: true, comment: '预防建议' })
  preventionSuggestion: string; // 预防建议

	@Column({ name: 'is_tomorrow', type: 'enum', enum: WeatherFileType, default: WeatherFileType.TODAY, comment: '是否是明天'})
	isTomorrow: number
}
